//
//  ScreenBar.m
//  Trucks
//
//  Created by 张飞飞 on 2018/6/24.
//  Copyright © 2018年 puyue.com. All rights reserved.
//

#import "ScreenBar.h"

@implementation ScreenBar

- (void)loadViews {
    self.distanceButton = [UIButton buttonWithTitle:@"距离" withImageName:@"fanye01" withBGColor:nil Withlayer:NO];
    self.distanceButton_buttonORDER = DEFAULT;
    self.distanceButton.tag = 1;
    self.distanceButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.distanceButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.distanceButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.distanceButton sizeToFit];
    self.distanceButton.titleEdgeInsets = UIEdgeInsetsMake(0, -self.distanceButton.imageView.frame.size.width - self.distanceButton.frame.size.width + self.distanceButton.titleLabel.frame.size.width, 0, 0);
    self.distanceButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -self.distanceButton.titleLabel.frame.size.width - self.distanceButton.frame.size.width + self.distanceButton.imageView.frame.size.width);
   
    
    self.reputationButton = [UIButton buttonWithTitle:@"好评" withImageName:@"fanye01" withBGColor:nil Withlayer:NO];
     self.reputationButton.tag = 2;
     self.reputationButton_buttonORDER = DEFAULT;
    self.reputationButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.reputationButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.reputationButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.reputationButton sizeToFit];
    self.reputationButton.titleEdgeInsets = UIEdgeInsetsMake(0, -self.reputationButton.imageView.frame.size.width - self.reputationButton.frame.size.width + self.reputationButton.titleLabel.frame.size.width, 0, 0);
    self.reputationButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -self.reputationButton.titleLabel.frame.size.width - self.reputationButton.frame.size.width + self.reputationButton.imageView.frame.size.width);
    
    self.lookButton = [UIButton buttonWithTitle:@"浏览量" withImageName:@"fanye01" withBGColor:[UIColor clearColor] Withlayer:NO];
     self.lookButton.tag = 3;
    self.lookButton_buttonORDER = DEFAULT;
    self.lookButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.lookButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.lookButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.lookButton sizeToFit];
    self.lookButton.titleEdgeInsets = UIEdgeInsetsMake(0, -self.lookButton.imageView.frame.size.width - self.lookButton.frame.size.width + self.lookButton.titleLabel.frame.size.width, 0, 0);
    self.lookButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -self.lookButton.titleLabel.frame.size.width - self.lookButton.frame.size.width + self.lookButton.imageView.frame.size.width);
    
    
    [self addSubview:self.distanceButton];
    [self addSubview:self.reputationButton];
    [self addSubview:self.lookButton];
    
    
    [[self rac_valuesForKeyPath:@"distanceButton_buttonORDER" observer:self] subscribeNext:^(id  _Nullable x) {
        
        if ([x intValue] == 0)
        {
            [self.distanceButton setImage:[UIImage imageNamed:@"fanye03"] forState:UIControlStateNormal];
        }
        else if ([x intValue] == 1)
        {
            [self.distanceButton setImage:[UIImage imageNamed:@"fanye02"] forState:UIControlStateNormal];
        }else{
            [self.distanceButton setImage:[UIImage imageNamed:@"fanye01"] forState:UIControlStateNormal];
        }
        [self.reputationButton setImage:[UIImage imageNamed:@"fanye01"] forState:UIControlStateNormal];
        [self.lookButton setImage:[UIImage imageNamed:@"fanye01"] forState:UIControlStateNormal];
    }];
    [[self rac_valuesForKeyPath:@"reputationButton_buttonORDER" observer:self] subscribeNext:^(id  _Nullable x) {
        
        
        if ([x intValue] == 0)
        {
            [self.reputationButton setImage:[UIImage imageNamed:@"fanye03"] forState:UIControlStateNormal];
        }
        else if ([x intValue] == 1)
        {
            [self.reputationButton setImage:[UIImage imageNamed:@"fanye02"] forState:UIControlStateNormal];
        }else
        {
            [self.reputationButton setImage:[UIImage imageNamed:@"fanye01"] forState:UIControlStateNormal];
        }
        [self.distanceButton setImage:[UIImage imageNamed:@"fanye01"] forState:UIControlStateNormal];
        [self.lookButton setImage:[UIImage imageNamed:@"fanye01"] forState:UIControlStateNormal];
        
        
        
    }];
    [[self rac_valuesForKeyPath:@"lookButton_buttonORDER" observer:self] subscribeNext:^(id  _Nullable x) {
        
       
        if ([x intValue] == 0)
        {
            [self.lookButton setImage:[UIImage imageNamed:@"fanye03"] forState:UIControlStateNormal];
        }
        else if ([x intValue] == 1)
        {
            [self.lookButton setImage:[UIImage imageNamed:@"fanye02"] forState:UIControlStateNormal];
        }
        else
        {
            [self.lookButton setImage:[UIImage imageNamed:@"fanye01"] forState:UIControlStateNormal];
        }
        [self.reputationButton setImage:[UIImage imageNamed:@"fanye01"] forState:UIControlStateNormal];
        [self.distanceButton setImage:[UIImage imageNamed:@"fanye01"] forState:UIControlStateNormal];
    }];
    self.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1.00];
}
- (void)layoutViews {
    [self.reputationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
        make.centerX.equalTo(self.mas_centerX);
        make.width.equalTo(@(GTFixWidthFlaot(50)));
    }];
    [self.distanceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
        make.left.equalTo(@(GTFixWidthFlaot(30)));
        make.width.equalTo(@(GTFixWidthFlaot(50)));
        
    }];
    [self.lookButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
        make.right.equalTo(@(GTFixWidthFlaot(-30)));
        make.width.equalTo(@(GTFixWidthFlaot(50)));
        
    }];
}
@end
